package unitest.Suite.tests
{
	import com.flashshe.ds.list.IList;
	import com.flashshe.ds.list.List;
	
	import flexunit.framework.Assert;
	
	
	
	public class TestList
	{
		protected var list:IList;
		
		
		[Before]
		public function initList():void
		{
			list = new List();
		}
		
		
		[Test]
		public function addElementAtBegin():void
		{			
			list.addAt(0, "b");
			Assert.assertTrue(list.size == 1);
			Assert.assertTrue(list.contains("b"));
			Assert.assertEquals(list.indexOf("b"), 0);

			list.addAt(0, "a");
			Assert.assertTrue(list.size == 2);
			Assert.assertTrue(list.contains("a"));
			Assert.assertEquals(list.indexOf("a"), 0);
			Assert.assertEquals(list.indexOf("b"), 1);
		}
		
		[Test]
		public function addElementAtLast():void
		{			
			list.add("a");
			Assert.assertTrue(list.size == 1);
			Assert.assertTrue(list.contains("a"));
			Assert.assertEquals(list.indexOf("a"), 0);
			
			list.add("b");
			Assert.assertTrue(list.size == 2);
			Assert.assertTrue(list.contains("b"));
			Assert.assertEquals(list.indexOf("a"), 0);
			Assert.assertEquals(list.indexOf("b"), 1);
		}
		
		[Test]
		public function addElementAtAnywhere():void
		{			
			addInitData();
			
			list.addAt(0, "first");
			list.addAt(5, "index5");
			Assert.assertTrue(list.size == 6);
			Assert.assertTrue(list.contains("index5"));
			Assert.assertTrue(list.contains("first"));
			Assert.assertEquals(list.indexOf("index5"), 5);
			Assert.assertEquals(list.indexOf("first"), 0);
		}
		
		[Test]
		public function getElement():void
		{			
			addInitData();
			
			Assert.assertTrue(list.getValueAt(0) == "john");
			Assert.assertTrue(list.getLast() == "rose");
			Assert.assertTrue(list.getValueAt(2) == "tom");
			
			list.add("last");
			Assert.assertTrue(list.getLast() == "last");
		}
		
		[Test]
		public function deleteElement():void
		{			
			addInitData();
			list.remove();
			Assert.assertTrue(list.size == 3);
			list.removeAt(0);
			Assert.assertTrue(list.size == 2);
			Assert.assertTrue(!list.contains("john"));
			list.removeAt(1);
			Assert.assertTrue(list.size == 1);
			Assert.assertTrue(list.contains("jack"));			
		}
		
		[Test]
		public function getDeletedElement():void
		{			
			addInitData();
			Assert.assertEquals(list.remove(), "rose");
			Assert.assertTrue(list.size == 3);
			Assert.assertEquals(list.removeAt(0), "john");			
			Assert.assertTrue(list.size == 2);
			Assert.assertTrue(!list.contains("john"));
			Assert.assertEquals(list.removeAt(1), "tom");	
			Assert.assertTrue(list.size == 1);
			Assert.assertTrue(list.contains("jack"));			
		}
		
		[Test]
		public function setElement():void
		{			
			addInitData();
			list.setValueAt(0, "first");
			list.setValueAt(1, "second");
			list.setValueAt(2, "third");
			list.setValueAt(3, "fourth");
			Assert.assertEquals(list.getValueAt(0), "first");
			Assert.assertEquals(list.getValueAt(1), "second");
			Assert.assertEquals(list.getValueAt(2), "third");
			Assert.assertEquals(list.getValueAt(3), "fourth");
			Assert.assertTrue(list.size == 4);				
		}
		
		[Test]
		public function clearAllElements():void
		{			
			addInitData();
			list.clear();
			Assert.assertTrue(list.size == 0);					
		}
		
		[Test]
		public function getElementIndex():void
		{			
			addInitData();			
			Assert.assertTrue(list.indexOf("john") == 0);	
			Assert.assertTrue(list.indexOf("jack") == 1);	
			Assert.assertTrue(list.indexOf("rose") == 3);	
		}
		
		[Test]
		public function size():void
		{
			list.clear();
			Assert.assertEquals(0, list.size);	
			list.add("john");
			list.add("jack");	
			Assert.assertEquals(2, list.size);	
		}
		
		[Test]
		public function isEmpty():void
		{
			list.clear();
			Assert.assertTrue(list.isEmpty());				
			list.add("john");	
			Assert.assertFalse(list.isEmpty());		
		}
		
		[Test]
		public function clear():void
		{
			list.add("john");	
			Assert.assertFalse(list.isEmpty());		
			list.clear();
			Assert.assertTrue(list.isEmpty());						
		}
		
		[Test]
		public function contains():void
		{
			list.clear();					
			list.add("john");
			Assert.assertTrue(list.contains("john"));	
		}
		
		private function addInitData():void
		{			
			list.add("john");
			list.add("jack");
			list.add("tom");			
			list.add("rose");						
		}
		
	}
}